<!-- 新增回款 -->
<template>
  <el-drawer v-model="drawerVisible" :close-on-click-modal="false" :destroy-on-close="true" size="1000px" title="创建回款计划">
    <el-form label-position="top" require-asterisk-position="right" :inline="true" class="form-inline-wrap">
      <el-form-item label="选择合同" class="is-required">
        <el-select v-model="params.contract" placeholder="请选择合同" clearable>
          <el-option v-for="item in contractList" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="选择回款计划" class="is-required">
        <el-input :prefix-icon="Search" placeholder="搜索回款计划模板"></el-input>

        <div class="plan-wrap">
          <div class="plan-type">
            <div
              class="name"
              :class="{ 'text-primary': currentType == index }"
              v-for="(item, index) in ['阶段', '文本']"
              :key="index"
              @click="currentType = index"
            >
              {{ item }}
            </div>
          </div>
          <div class="plan-template">
            <el-radio-group v-model="params.plan">
              <el-radio v-for="(item, index) in templateList" :key="index" :value="item.id" size="large">{{
                item.name
              }}</el-radio>
            </el-radio-group>
          </div>
        </div>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
import { ref, reactive, defineEmits } from "vue";
import { ElMessage } from "element-plus";

const emit = defineEmits(["close", "refresh"]);

interface DrawerProps {
  id: number;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref({});
const params = ref({});

// 合同列表
const contractList = ref([
  { label: "111", value: 1 },
  { label: "222", value: 2 }
]);

// 当前类型
const currentType = ref(0);

// 模板列表
const templateList = ref([
  { id: 1, name: "111" },
  { id: 2, name: "222" }
]);

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params;
  drawerVisible.value = true;
};

// 提交数据（新增/编辑）
const ruleFormRef = ref();
const handleSubmit = () => {
  ruleFormRef.value!.validate(async valid => {
    if (!valid) return;
    try {
      //   await drawerProps.value.api!(drawerProps.value.row);
      //   ElMessage.success({ message: `${drawerProps.value.title}用户成功！` });
      //   drawerVisible.value = false;
      emit("refresh");
    } catch (error) {
      console.log(error);
    }
  });
};

const close = () => {
  drawerVisible.value = false;
  emit("close");
};

defineExpose({
  acceptParams
});
</script>

<style lang="scss" scoped>
.plan-wrap {
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(186, 191, 197, 0.4);
  border-radius: 4px;
  padding: 8px;

  .plan-type {
    display: flex;
    border: 1px solid #f4f4f5;
    border-radius: 4px;
    line-height: 32px;

    .name {
      flex: 1;
      text-align: center;
      font-size: 12px;
      cursor: pointer;

      &:first-child {
        border-right: 1px solid #f4f4f5;
      }
    }
  }

  .el-radio-group {
    width: 100%;
    margin: 8px 8px 0 8px;
    .el-radio.el-radio--large {
      width: 100%;
    }
  }
}
</style>
